package win.start.web;

import javax.validation.Valid;

import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import win.start.pojo.BasePojo;
import win.start.pojo.OnePojo;

@RestController
@RequestMapping("/demo")
public class DemoController {

	@RequestMapping("/testa")
	public Object testA(@Valid BasePojo pojo, BindingResult result) {
		if (result.hasErrors()) {
			result.getAllErrors().forEach(System.out::println);
			System.out.println("-----------");
			result.getAllErrors().forEach(e -> {
				System.out.println(e.getDefaultMessage());
			});
		}
		return pojo;
	}

	@RequestMapping("/testb")
	public Object testB(@Valid OnePojo pojo, BindingResult result) {
		if (result.hasErrors()) {
			result.getAllErrors().forEach(System.out::println);
			System.out.println("-----------");
			result.getAllErrors().forEach(e -> {
				System.out.println(e.getDefaultMessage());
			});
		}
		return pojo;
	}
}
